package com.wr.controller;

import com.wr.activeMQ.Producer;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.jms.Destination;
import javax.servlet.http.HttpServletRequest;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

@Controller
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.wr")
public class UploadFileController {
    private final Producer producer;

    @Autowired
    public UploadFileController(Producer producer) {
        this.producer = producer;
    }

    /**
     * 批量上传图片-消息队列
     * @param request
     * @return
     */
    @RequestMapping("/uploadFile")
    @ResponseBody
    public Map<String,Object> uploadFile(HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        Destination destination = new ActiveMQQueue("mytest.queue");
        producer.sendMessage(destination,fileMap);
        System.out.println(11111);
        map.put("result","success");
        return map;
    }
}
